-- forbid_magic_damage
-- Created by wangy Jun/28/2016
-- 对敌人造成N点伤害，附带禁魔力场效果
-- 被杀死的敌人，变为真实形态

return {
    apply = function(source, target, classId, value)
        if target.type ~= OBJECT_TYPE_MONSTER then
            -- 目标必须是怪物
            return;
        end

        -- 传入攻击者信息
        local assailantInfo = {
            ["property_id"] = classId,
        };

        -- 如果有伤害加成
        local damage = tonumber(value);
        if PropertyM.query(classId, "target") ~= PROPERTY_SELF then
            local prop = PropM.combine(source, "property_damage", 1);
            damage = PropM.apply(prop, damage);
        end

        -- 修正伤害值
        damage = PropertyM.fixPropertyDamage(source, target, classId, damage);

        CombatM.doDamage(source, target, damage, 0, false, { assailantInfo = assailantInfo, });

        local bonus;
        if target:isDead() then
            local rand = DungeonM.getRandSeed("forbid_magic_damage") % 1000;
            local itemId;
            local baseId = target:query("base_class_id");
            local pieces = { [91] = 7414, [92] = 7415, [93] = 7416, [94] = 7417, [95] = 7418, };

            if rand < 100 and BuildingBonusM.getFieldStat("diamond_statue") < 2 then
                itemId = 7419;
                BuildingBonusM.addFieldStat("diamond_statue", 1);
            else
                itemId = pieces[baseId];
            end

            if type(itemId) == "number" then
                bonus = { 1, itemId, 1, };
                BonusM.doBonus(bonus, "crystal_ball");
            end
        end

        -- 抛出道具攻击事件
        EventMgr.fire(event.PROPERTY_ATTACK, {
            ["classId"] = classId,
            ["target"]  = target,
            ["bonus"]   = bonus,
        });
    end,
}